/**
 * Created by jenking on 15-3-26.
 */
define([
    "jquery",
    "underscore",
    "helper/util",
    'home/template',
    'text!text_path/demo.html',
    'css!css_path/plugins',
    "domReady!"

],function($,_,util,tplview,demoViewTemplate){

    function HomeDo(){
        this.mainBox=$("#mainBox");
        this.dateInfo=$("#dateInfo");
        this.start=new Date().getTime();
        this.cost_time=$("#cost_time");
        this.listener=null;
    };

    HomeDo.prototype.settings=function(){
        _.templateSettings = {
            interpolate: /\{\{(.+?)\}\}/g
        };
    };

    HomeDo.prototype.tplDemo=function(){
        var t=this;

        //underscore template
        var compiled=_.template(demoViewTemplate);
        var msg=compiled({
            msg:"hello my template"
        });

        //tmod template
        var data={
            time:new Date().getTime()
        }

        var res=tplview("listview",data);

        t.listener=setInterval(function(){
            var sec=new Date().getTime()- t.start;
            var costtime=util.cost_time(sec);
            t.cost_time.html(costtime);
        },10);

        t.dateInfo.html(msg+""+res).find("span").on("click",function(){
            clearInterval(t.listener);
        });
    };

    HomeDo.prototype.render=function(){
        var t=this;
        t.tplDemo();
        t.mainBox.removeClass("displayNone");
    }

    HomeDo.prototype.init=function(){
        this.settings();
        this.render();
    }

    return new HomeDo();
});